@echo off
setlocal enabledelayedexpansion

echo ========================================
echo 图书管理系统 - 完整测试套件
echo ========================================

set "TIMESTAMP=%date:~0,4%-%date:~5,2%-%date:~8,2%_%time:~0,2%-%time:~3,2%-%time:~6,2%"
set "REPORT_DIR=test-reports\%TIMESTAMP%"
mkdir "%REPORT_DIR%" 2>nul

echo [1/6] 代码质量检查...
call npm run lint:check > "%REPORT_DIR%\lint.log" 2>&1
set "lint_result=%errorlevel%"

echo [2/6] TypeScript 类型检查...
call npm run type-check > "%REPORT_DIR%\type-check.log" 2>&1
set "type_result=%errorlevel%"

echo [3/6] 单元测试...
call npm run test:unit:coverage > "%REPORT_DIR%\unit-tests.log" 2>&1
set "unit_result=%errorlevel%"

echo [4/6] 组件测试...
call npx cypress run --component > "%REPORT_DIR%\component-tests.log" 2>&1
set "component_result=%errorlevel%"

echo [5/6] E2E 测试...
call npm run test:e2e:headless > "%REPORT_DIR%\e2e-tests.log" 2>&1
set "e2e_result=%errorlevel%"

echo [6/6] HarmonyOS 测试...
call npm run test:harmonyos > "%REPORT_DIR%\harmonyos-tests.log" 2>&1
set "harmonyos_result=%errorlevel%"

echo.
echo ========================================
echo 测试结果汇总
echo ========================================

if %lint_result%==0 (echo ✅ 代码质量检查: 通过) else (echo ❌ 代码质量检查: 失败)
if %type_result%==0 (echo ✅ 类型检查: 通过) else (echo ❌ 类型检查: 失败)
if %unit_result%==0 (echo ✅ 单元测试: 通过) else (echo ❌ 单元测试: 失败)
if %component_result%==0 (echo ✅ 组件测试: 通过) else (echo ❌ 组件测试: 失败)
if %e2e_result%==0 (echo ✅ E2E测试: 通过) else (echo ❌ E2E测试: 失败)
if %harmonyos_result%==0 (echo ✅ HarmonyOS测试: 通过) else (echo ❌ HarmonyOS测试: 失败)

echo.
echo 详细报告位置: %REPORT_DIR%
echo 覆盖率报告: coverage\lcov-report\index.html

set /a "total_failures=%lint_result%+%type_result%+%unit_result%+%component_result%+%e2e_result%+%harmonyos_result%"
if %total_failures%==0 (
    echo.
    echo 🎉 所有测试通过！
    exit /b 0
) else (
    echo.
    echo ❌ 有 %total_failures% 个测试失败
    exit /b 1
)